/*
 * @Author: Jiraiya
 * @Date: 2020-05-12 17:51:34
 * @LastEditors: Jiraiya
 * @LastEditTime: 2020-05-12 17:52:36
 * @Description: 
 */
/**
 * @description: 
 * @param {Array | Object} children 子组件
 * @param {Function} func 回调函数
 * @param {Object} context 上下文 (回调中的this)
 * @return: 
 */
function mapChildren(children, func, context){
    if(children == null) return children;
    const result = [];
    mapIntoWithKeyPrefixInternal(children, result, null, func, context);
    return result;
}

function escapeUserProvidedKey(text) {
    return ('' + text).replace(/\/+/g, '$&/');
}

function mapIntoWithKeyPrefixInternal(children, array, prefix, func, context){
    let escapedPrefix = '';
    if(prefix !== null){
        // 校验key合法性
        escapedPrefix = escapeUserProvidedKey(prefix) + '/';
    }

    // 从变量池获取一个变量
    const traverseContext = getPooledTraverseContext(
        array,
        escapedPrefix,
        func,
        context,
    )
    //处理所有子节点
    traverseAllChildren(children, mapSingleChildIntoContext, traverseContext);
}